Gradle plugin for generating localized string resources
Gradle plugin for generating localized string resources
This plugin generates Android string resource XML files from CSV file. Generation has to be invoked as additional gradle task.
translatable="false"
XML attributeAdd dependency to the top-level build.gradle
file.
Your file should look like this:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.+'
classpath 'pl.droidsonroids.gradle.localization:android-gradle-localization-plugin:1.0.+'
}
}
Apply plugin and add configuration to build.gradle
of the application, eg:
apply plugin: 'localization'
localization
{
csvFile=file('translations.csv')
OR
csvFileURI='https://docs.google.com/spreadsheets/d/<key>/export?format=csv'
}
csvFileURI
can be any valid URI, not necessarily Google Docs' one
Invoke localization
gradle task. Task may be invoked from commandline or from Android Studio GUI.
./gradlew localization
(or gradlew.bat localization
on Windows)View->Tool Windows->Gradle
and double click localization
Non existent folders will be created. WARNING existing XML files will be overwritten.
The following CSV file:
name,default ,pl ,comment ,translatable
file,File ,"Plik" ,file label,
app ,Application,,,false
will produce 2 XML files:
values/strings.xml
:<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="file">File</string><!-- file label -->
<string name="app" translatable="false">Application</string>
</resources>
values-pl/strings.xml
:<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="file">Plik</string><!-- file label -->
</resources>
localization
extension in build.gradle
can contain several configuration options. All of them
except CSV file location are optional and has reasonable default values.
CSV file location. Exactly one of them must be specified:
csvFile
- CSV File, Gradle's file()
can be used to retrieve files by path relative to module location or absolutecsvFileURI
- CSV file URICSV format:
defaultColumnName
- default='default', column name which corresponds to default localization
(values
folder)csvStrategy
- default=null
(library default strategy, equivalent of
CSVStrategy.DEFAULT_STRATEGY)
The following options turn off some character escaping and substitutions, can be useful if you have something already escaped in CSV:
escapeApostrophes
- default=true, if set to false apostrophes ('
) won't be escapedescapeQuotes
- default=true, if set to false double quotes ("
) won't be escapedescapeNewLines
- default=true, if set to false newline characters won't be escapedescapeBoundarySpaces
- default=true, if set to false leading and trailing spaces
won't be escaped so they will be effectively removed at compile timeconvertTripleDotsToHorizontalEllipsis
- default=true, if set to false triple dots (...
) won't be converted to ellipsis entity …
escapeSlashes
- default=true, if set to false slashes (\
) won't be escapednormalizationForm
- default=Normalizer.Form.NFC
if set to null
Unicode normalization won't be performed, see (javadoc of Normalizer)[http://docs.oracle.com/javase/8/docs/api/java/text/Normalizer.Form.html#NFC]
for more detailstagEscapingStrategy
- default=IF_TAGS_ABSENT, defines X(H)TML tag brackets (< and >) escaping strategy
possible values:
Advanced options:
ignorableColumns
- default=[], columns from that list will be ignored during parsingallowNonTranslatableTranslation
- default=false, if set to true resources marked
non-translatable but translated are permittedallowEmptyTranslations
- default=false, if set to true then empty values are permittedMIT License
See LICENSE file.